package com.aspros.testandroidtab;

import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.widget.TextView;

public abstract class BaseActivity extends AppCompatActivity {
    private Toolbar mToolbar;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        init();
    }

    protected abstract int getLayoutId();
    protected abstract void initViews();
    protected abstract String getTitleString();

    private void init()
    {
        //setContentView(R.layout.activity_base);
        setContentView(getLayoutId());

        mToolbar = findViewById(R.id.toolbar);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            mToolbar.setTitle("");
        }

        setSupportActionBar(mToolbar);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().setStatusBarColor(getResources().getColor(R.color.appcolor));
        }

        // set Title
        TextView tv = findViewById(R.id.title);
        tv.setText(getTitleString());

        initViews();
    }

    protected void setToolbarAndStatusColor(int resId)
    {
        mToolbar.setBackgroundColor(resId);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().setStatusBarColor(resId);
        }
    }
}
